//
//  UIView+TapEvent.m
//  HuiMe
//
//  Created by 李坤 on 2018/5/7.
//  Copyright © 2018年 程强. All rights reserved.
//

#import "UIView+TapEvent.h"
#import <objc/runtime.h>

static char kUIViewTouchKey;

@implementation UIView (TapEvent)
@dynamic tapBlock;
- (void)singleClick:(void(^)(void))block
{
    objc_setAssociatedObject(self, &kUIViewTouchKey, block, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click:)];
    [self addGestureRecognizer:tap];
}
- (void)click:(UITapGestureRecognizer *)ger
{
    if (self.tapBlock) {
        self.tapBlock();
    }
}
- (void(^)(void))tapBlock
{
    return objc_getAssociatedObject(self, &kUIViewTouchKey);
}
@end
